package com.gohi.main.interceptor;


import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * 用户是否登录拦截器
 * */
public class UserInterceptor extends AbstractInterceptor {

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		// 获取请求的action名称
//		String actionName = invocation.getInvocationContext().getName();
		//是否登录
		String method = invocation.getProxy().getMethod();
		//System.err.println(method);
		if(method.equals("orderdetail")){
			return invocation.invoke();
		}
		Map map = invocation.getInvocationContext().getSession();
		if(null == map.get("user")){
			HttpServletRequest request = ServletActionContext.getRequest();
			request.setAttribute("url", "user!index.do");
			request.setAttribute("alert", "您尚未登陆！");
			return "ERROR";
		}
		return invocation.invoke();
	}
	

}
